Skip to content

[ShanaBoo] Show new liquidation price when adding or removing margin#207

Open
genesisrevelationinc-debug wants to merge 4 commits into
capofficial:mainfrom
genesisrevelationinc-debug:shanaboo-fix-4
Open

[ShanaBoo] Show new liquidation price when adding or removing margin#207
genesisrevelationinc-debug wants to merge 4 commits into
capofficial:mainfrom
genesisrevelationinc-debug:shanaboo-fix-4

Conversation

@genesisrevelationinc-debug
Copy link
Copy Markdown

ShanaBoo Autonomous Fix

This PR was automatically generated by ShanaBoo Earn Engine to claim the $50.00 bounty on this issue.

Source: Github | Task: 1482288184

Closes #4


Auto-submitted by ShanaBoo CNS — NVIDIA NIM + Microsoft Agent Framework

Copilot AI review requested due to automatic review settings May 25, 2026 04:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds utility helpers for input focus and liquidation-price estimation, and introduces a new “Add/Remove Margin” modal that displays current vs. projected liquidation price.

Changes:

  • Added focusInput and getLiquidationPrice exports to shared utils.
  • Added new AddMargin.svelte modal UI and submit handler skeleton.
  • Wired modal to stores to compute/display updated liquidation price.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
src/lib/utils.js Adds focus helper and liquidation price calculator to support margin-adjust UI.
src/components/modals/AddMargin.svelte New modal for adding/removing margin and previewing liquidation price changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +35
async function handleSubmit() {
errors = {}
if (!amount) {
</div>
</div>

<div class='row'>
<div class='label'>Current Liquidation Price</div>
<div class='value'>{currentLiquidationPrice ? `$${formatNumber(currentLiquidationPrice)}` : '-'}</div>
</div>

{#if amount}
<div class='row'>
<div class='label'>New Liquidation Price</div>
<div class='value'>{newLiquidationPrice ? `$${formatNumber(newLiquidationPrice)}` : '-'}</div>
</div>
{/if}

<div class='buttons'>
<Button isLoading={loading} label={data.isAdding ? 'Add Margin' : 'Remove Margin'} />
</div>
margin-bottom: 20px;
Comment on lines +11 to +12
$: newLiquidationPrice = data.isAdding ? getLiquidationPrice(data.position, $addMarginAmount) : getLiquidationPrice(data.position, -$removeMarginAmount)
$: currentLiquidationPrice = data.position.liquidationPrice

async function handleSubmit() {
errors = {}
if (!amount) {

<div class='row'>
<div class='label'>Current Liquidation Price</div>
<div class='value'>{currentLiquidationPrice ? `$${formatNumber(currentLiquidationPrice)}` : '-'}</div>
{/if}

<div class='buttons'>
<Button isLoading={loading} label={data.isAdding ? 'Add Margin' : 'Remove Margin'} />
Comment thread src/lib/utils.js
Comment on lines +1 to 18
export function focusInput(node) {
node.focus()
}

export function getLiquidationPrice(position, marginChange) {
if (!position || !position.size) return null

const newMargin = position.margin + marginChange
if (newMargin <= 0) return null

// Liquidation price formula: entryPrice +/- (entryPrice * newMargin / size)
// For longs: entryPrice * (1 - newMargin/size) - for shorts: entryPrice * (1 + newMargin/size)
const direction = position.isLong ? 1 : -1
const liquidationPrice = position.entryPrice * (1 - direction * newMargin / position.size)

return liquidationPrice
}
import { formatForDisplay } from './formatters'
Comment thread src/lib/utils.js
Comment on lines +5 to +8
export function getLiquidationPrice(position, marginChange) {
if (!position || !position.size) return null

const newMargin = position.margin + marginChange
Comment thread src/lib/utils.js
// Liquidation price formula: entryPrice +/- (entryPrice * newMargin / size)
// For longs: entryPrice * (1 - newMargin/size) - for shorts: entryPrice * (1 + newMargin/size)
const direction = position.isLong ? 1 : -1
const liquidationPrice = position.entryPrice * (1 - direction * newMargin / position.size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show new liquidation price when adding or removing margin

2 participants